package com.eduService.teacher.controller.home;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.eduService.teacher.entity.EduCourse;
import com.eduService.teacher.entity.EduTeacher;
import com.eduService.teacher.service.IEduCourseService;
import com.eduService.teacher.service.IEduTeacherService;
import com.eduService.teacher.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/hometeacher")
public class homeTeacherController {

    @Autowired
    private IEduTeacherService teacherService;

    @Autowired
    private IEduCourseService courseService;

    @GetMapping("pageteacher/{page}/{limit}")
    public R pageTeacher(@PathVariable("page") Long page ,@PathVariable("limit") Long limit){
        Page<EduTeacher> tpage = new Page<>(page,limit);
        teacherService.page(tpage,null);
        List<EduTeacher> records = tpage.getRecords();
        long total = tpage.getTotal();
        return R.ok().data("total",total).data("data",records);
    }

    /**
     * 根据教师id获取教师的信息与授课
     *
     * */
    @GetMapping("getTeacherInfo/{id}")
    public R getTeacherInfo(@PathVariable("id")String id){
        EduTeacher eduTeacher = teacherService.getById(id);
        QueryWrapper<EduCourse> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("teacher_id",id);
        List<EduCourse> courseList = courseService.list(queryWrapper);
        return R.ok().data("teacher",eduTeacher).data("courseList",courseList);
    }

}
